<?php

class sfWidgetFormSelectCheckboxInline extends sfWidgetFormSelectCheckbox
{
    protected function formatChoices($name, $value, $choices, $attributes)
    {
        $inputs = array();
        foreach ($choices as $key => $option)
        {
            $baseAttributes = array(
                'name'  => $name,
                'type'  => 'checkbox',
                'value' => self::escapeOnce($key),
                'id'    => $id = $this->generateId($name, self::escapeOnce($key)),
            );

            if ((is_array($value) && in_array(strval($key), $value)) || (is_string($value) && strval($key) == strval($value)))
            {
                $baseAttributes['checked'] = 'checked';
            }

            $inputs[$id] = array(
                'input' => $this->renderTag('input', array_merge($baseAttributes, $attributes)),
                'label' => self::escapeOnce($option),
            );
        }

        return call_user_func($this->getOption('formatter'), $this, $inputs);
    }

    public function formatter($widget, $inputs)
    {
        $rows = '';
        foreach ($inputs as $input)
        {
          $rows .= '<label class="checkbox">'.$input['input'].$this->getOption('label_separator').$input['label'].'</label>';
        }

        return $rows;
    }
}
